package tau_sadna.tau_map;

import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class GpsIcon extends ImageView {

	static final int STATE_OFF = 0;
	static final int STATE_PENDING = 1;
	static final int STATE_ON = 2;
	
	private MainActivity main;
	int state;
	
	Drawable off_icon;
	Drawable pending_icon1;
	Drawable pending_icon2;
	Drawable on_icon;
	
	Animation myFadeInAnimation;
	
	public GpsIcon(MainActivity main) {
		super(main);
		this.main = main;
		this.off_icon = main.getResources().getDrawable(R.drawable.gps_off_icon);
		this.pending_icon1 = main.getResources().getDrawable(R.drawable.gps_pending_icon1);
		this.pending_icon2 = main.getResources().getDrawable(R.drawable.gps_pending_icon2);
		this.on_icon = main.getResources().getDrawable(R.drawable.gps_icon2);
		myFadeInAnimation = AnimationUtils.loadAnimation(this.main, R.anim.fade);

		this.setState(STATE_OFF);
		
	}
	
	public synchronized void setState(int state) {
		this.state = state;
		switch (this.state) {
			case STATE_OFF:
				this.setBackgroundResource(R.drawable.gps_off_icon);
				this.clearAnimation();
				break;
			case STATE_PENDING:
				this.setBackgroundResource(R.drawable.movie);
				AnimationDrawable anim = (AnimationDrawable) this.getBackground();
				anim.start();
				break;
			case STATE_ON:
				this.setBackgroundResource(R.drawable.gps_icon2);
				this.clearAnimation();
				break;
		}
		
	}

	

}
